package com.hskn.hss.module.tlfactypeitem.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.domain.BaseEntity;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.tlfacilitietype.entity.TlFacilitiesType;
import com.hskn.hss.module.tlfactypeitem.entity.TlFacilitiesTypeItems;
import com.hskn.hss.module.tlfactypeitem.mapper.TlFacilitiesTypeItemsMapper;
import com.hskn.hss.module.tlfactypeitem.service.ITlFacilitiesTypeItemsService;
import com.hskn.hss.utils.Tools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-12
 */
@Api(tags = {"-tl_facilities_type_items"}, description = "设施类型小类")
@Slf4j
@RestController
@RequestMapping("/hss/tlfacilitiestypeitems")
public class TlFacilitiesTypeItemsController {

    @Autowired
    ITlFacilitiesTypeItemsService tlFacilitiesTypeItemsService;

    @SysLog(businessType = BusinessType.INSERT, tableName = "tl_facilities_type_items", bean = TlFacilitiesTypeItems.class, beanMapper = TlFacilitiesTypeItemsMapper.class, names = "itemtypename")
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public AjaxResult<Object> insert(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return tlFacilitiesTypeItemsService.insert(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "tl_facilities_type_items", idKey = "id", bean = TlFacilitiesTypeItems.class, beanMapper = TlFacilitiesTypeItemsMapper.class, names = "itemtypename")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return tlFacilitiesTypeItemsService.update(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.DELETE, tableName = "tl_facilities_type_items", idKey = "id", bean = TlFacilitiesTypeItems.class, beanMapper = TlFacilitiesTypeItemsMapper.class, names = "itemtypename")
    @RequestMapping(value = "deletebyid", method = RequestMethod.POST)
    public AjaxResult<Object> deletebyid(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return tlFacilitiesTypeItemsService.deletebyid(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("删除失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.DELETE, tableName = "tl_facilities_type_items", idKey = "ids", bean = TlFacilitiesTypeItems.class, beanMapper = TlFacilitiesTypeItemsMapper.class, names = "itemtypename")
    @ApiOperation(value = "批量删除接口", notes = "批量删除")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = TlFacilitiesType.class)
    })
    @RequestMapping(value = "deletebatchbyid", method = RequestMethod.POST)
    public AjaxResult<Object> deletebatchbyid(@RequestBody @Validated TlFacilitiesTypeItems tlFacilitiesTypeItems) {

        try {
            return tlFacilitiesTypeItemsService.deletebatchbyid(tlFacilitiesTypeItems);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("删除失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getSelectList", method = RequestMethod.POST)
    public AjaxResult<Object> getSelectList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        return AjaxResult.success(tlFacilitiesTypeItemsService.getSelectList(params));
    }

    @RequestMapping(value = "getDetail", method = RequestMethod.POST)
    public AjaxResult<Object> getDetail(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        TlFacilitiesTypeItems tlFacilitiesTypeItems = null;
        try {
            tlFacilitiesTypeItems = tlFacilitiesTypeItemsService.getDetail(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
        return AjaxResult.success(tlFacilitiesTypeItems);

    }

    @RequestMapping(value = "getList", method = RequestMethod.POST)
    public AjaxResult<Object> getList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            BaseEntity entity = new BaseEntity();
            JSONObject json = tlFacilitiesTypeItemsService.getList(entity, params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }
}

